//certificate_update.js @author zlx

const request = require('../../../utils/requestAjax.js')
const app = getApp()
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    checked:true,
    userInfo: {userName:'ww',roleId:1},
    id: '',
    certificate: {},
    deleteAttachmentList: [],
    // //授权弹窗是否弹出
    // authorizeShow: false,
    //选择文件的list
    tempFilePathList: [],
    certTypeList: [],
    //证书类型是否已选择
    // certTypeIsSelect: false,
    //证书类型选择第几个
    certTypeIndex: -1,
    //起始日期是否已选择
    // beginDateIsSelect: false,
    //终止日期是否已选择
    // endDateIsSelect: false,
    nowDate: '',
    fileList:[]
  },

  onLoad: function (options) {
    this.setData({
     // userInfo: wx.getStorageSync('userInfo'),
      certTypeList: wx.getStorageSync('baseData')['3'],
      nowDate: app.getNowDate()
    })

    if (options && options.id) {
      this.setData({
        id: parseInt(options.id)
      })
    }
    this.getCertificate()

  },

  onReady: function () {

  },

  onShow: function () {

  },

  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.setData({
      tempFilePathList: []
    })
    this.getCertificate(function () {
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh()
    })
  },

  onReachBottom: function () {

  },

  // onShareAppMessage: function () {

  // },

  //证书类型选择
  bindCertTypePickerChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      // certTypeIsSelect: true,
      certTypeIndex: e.detail.value,
    })

    this.setData({
      'certificate.certType': this.data.certTypeList[this.data.certTypeIndex].codeDetail
    })
    // console.log(this.data.certificate)
  },

  bindCertameInput: function (e) {
    this.setData({
      'certificate.certName': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindCertIdInput: function (e) {
    this.setData({
      'certificate.certId': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindProjectNameInput: function (e) {
    this.setData({
      'certificate.projectName': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindCertUnitInput: function (e) {
    this.setData({
      'certificate.certUnit': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  //起始日期选择
  bindBeginDateChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      // beginDateIsSelect: true,
      'certificate.beginDate': e.detail.value
    })
  },

  //终止日期选择
  bindEndDateChange: function (e) {
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      // endDateIsSelect: true,
      'certificate.endDate': e.detail.value
    })
  },

  bindNoteInput: function (e) {
    this.setData({
      'certificate.note': e.detail.value
    })
    // console.log(this.data.certificate)
  },

  bindTempFileNameInput: function (e) {
    var index = e.currentTarget.dataset.index
    var tempFilePathListIndexKeyName = 'tempFilePathList[' + index + '].name'
    var tempFilePathListIndexKeyFileType = this.data.tempFilePathList[index].name.substring(this.data.tempFilePathList[index].name.lastIndexOf('.'))
    this.setData({
      [tempFilePathListIndexKeyName]: e.detail.value + tempFilePathListIndexKeyFileType
    })
    // console.log(this.data.tempFilePathList)
  },

  bindTempFileNameInputBlur: function (e) {
    var index = e.currentTarget.dataset.index
    let _this = this
    var fileName = _this.data.tempFilePathList[index].name.substring(0, _this.data.tempFilePathList[index].name.lastIndexOf('.'))
    //输入新增附件名为空判断
    if (fileName == '') {
      var tempFilePathListIndexKeyName = 'tempFilePathList[' + index + '].name'
      var tempFilePathListIndexKeyFileType = _this.data.tempFilePathList[index].name.substring(_this.data.tempFilePathList[index].name.lastIndexOf('.'))
      _this.setData({
        [tempFilePathListIndexKeyName]: _this.data.tempFilePathList[index].initFileName + tempFilePathListIndexKeyFileType
      })
      wx.showModal({
        title: '系统提示',
        content: '附件名不能为空，请重新输入',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    //输入新增附件名重复判断
    for (var i = 0; i < _this.data.tempFilePathList.length; i++) {
      var hasTempFilePath = _this.data.tempFilePathList[i]
      if (hasTempFilePath != '') {
        if (hasTempFilePath.name.toLowerCase() == _this.data.tempFilePathList[index].name.toLowerCase() && i != index) {

          var tempFilePathListIndexKeyName = 'tempFilePathList[' + index + '].name'
          var tempFilePathListIndexKeyFileType = _this.data.tempFilePathList[index].name.substring(_this.data.tempFilePathList[index].name.lastIndexOf('.'))
          _this.setData({
            [tempFilePathListIndexKeyName]: _this.data.tempFilePathList[index].initFileName + tempFilePathListIndexKeyFileType
          })

          wx.showModal({
            title: '系统提示',
            content: '新增附件名重复，请重新输入',
            showCancel: false,
            success(res) {
              if (res.confirm) {} else if (res.cancel) {}
            }
          })
        }
      }
    }
    //和已有文件存在相同文件判断
    _this.data.certificate.attachmentList.forEach(element => {
      if (element.attachmentName.toLowerCase() == _this.data.tempFilePathList[index].name.toLowerCase()) {
        wx.showModal({
          title: '系统提示',
          content: '新增附件名与已有附件名相同，确定选择上传时会覆盖相同附件',
          showCancel: true,
          success(res) {
            if (res.confirm) {} else if (res.cancel) {
              var tempFilePathListIndexKeyName = 'tempFilePathList[' + index + '].name'
              var tempFilePathListIndexKeyFileType = _this.data.tempFilePathList[index].name.substring(_this.data.tempFilePathList[index].name.lastIndexOf('.'))
              _this.setData({
                [tempFilePathListIndexKeyName]: _this.data.tempFilePathList[index].initFileName + tempFilePathListIndexKeyFileType
              })

            }
          }
        })
      }
    })
  },

  // 下载文件
  downloadFile: function (attachmentUrl,attachmentName){
    return new Promise(function(resolve, reject){
      wx.downloadFile({
        url:app.globalData.filePrefix + '/' + attachmentUrl,
        success(res){
          resolve({
            attachmentUrl,
            name:attachmentName,
            path: res.tempFilePath
          })
        }
      })
    })
  },

  GetFileType(path = '') {
    return path.substring(path.lastIndexOf(".") + 1, path.length).toLocaleLowerCase();
  },
  IsImage(name){
    return this.GetFileType(name) === 'png'||
        this.GetFileType(name) === 'jpg' ||
        this.GetFileType(name) === 'jpeg' ||
        this.GetFileType(name) === 'gif'
  },
  ChooseImage() {
    var that = this;
    wx.chooseMessageFile({
      count: 4,
      type: 'all',
      success: (res) => {
        var tempFiles = res.tempFiles.map(item => (
            {
              data:item,
              isImage:that.IsImage(item.path)
            }
        ))
        console.log(tempFiles);
        if (this.data.fileList.length != 0) {
          this.setData({
            // const tempFilePaths = res.tempFilePaths
            fileList: this.data.fileList.concat(tempFiles)
          })
        } else {
          this.setData({
            fileList: tempFiles
          })
        }
      }
    });
  },
  ViewImage(e) {
    console.log(this.data.fileList)
    wx.previewImage({
      urls: this.data.fileList.map(item => item.data.path),
      current: e.currentTarget.dataset.url
    });
  },
  DelImg(e) {
    this.data.fileList.splice(e.currentTarget.dataset.index, 1);
    this.setData({
      fileList: this.data.fileList
    })
  },
  getCertificate: function (then) {
    let _this = this
    request.requestAjax('/getCertificate', {
        "id": this.data.id
      }, '正在加载',
      //请求成功回调
      function (res) {
        // console.log(res)
        _this.setData({
          certificate: res.data
        })
        for (var i = 0; i < _this.data.certTypeList.length; i++) {
          if (_this.data.certificate.certType == _this.data.certTypeList[i].codeDetail) {
            _this.setData({
              certTypeIndex: i
            })
          }
        }
        //清空新增附件 删除附件
        _this.setData({
          tempFilePathList: [],
          deleteAttachmentList: []
        })
        if (then) {
          then()
        }
      },
      //请求失败回调
      function (res) {
        wx.showModal({
          title: '系统提示',
          content: res.msg,
          showCancel: false,
          success(res) {
            if (res.confirm) {} else if (res.cancel) {}
          }
        })
        if (then) {
          then()
        }
      })
  },

  //点击附件＋
  addAttach: function (e) {
    //在最后添加一个元素
    this.data.tempFilePathList.push('')
    //由于上面的方法无法刷新页面 所以需要下面紧跟再setData
    this.setData({
      tempFilePathList: this.data.tempFilePathList
    })
    // console.log(this.data.tempFilePathList)
    wx.pageScrollTo({
      selector: '#save',
      duration: 200
    })
  },

  //点击已有附件×
  deleteAttach: function (e) {
    //从index开始删除一个元素
    this.data.certificate.attachmentList.splice(e.currentTarget.dataset.index, 1)
    //由于上面的方法无法刷新页面 所以需要下面紧跟再setData
    this.setData({
      'certificate.attachmentList': this.data.certificate.attachmentList
    })
    var attachment = {}
    attachment.id = e.currentTarget.dataset.id
    attachment.attachmentUrl = e.currentTarget.dataset.url
    this.data.deleteAttachmentList.push(attachment)
  },

  //点击新增附件×
  reduceAttach: function (e) {
    //从index开始删除一个元素
    this.data.tempFilePathList.splice(e.currentTarget.dataset.index, 1)
    //由于上面的方法无法刷新页面 所以需要下面紧跟再setData
    this.setData({
      tempFilePathList: this.data.tempFilePathList
    })
    // console.log(this.data.tempFilePathList)
  },

  //点击选择文件
  selectFile: function (e) {
    var index = e.currentTarget.dataset.index
    let _this = this
    wx.chooseMessageFile({
      count: 1,
      success(res) {
        // console.log(res)
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePath = res.tempFiles[0]
        //文件后缀名
        var fileType = tempFilePath.name.substring(tempFilePath.name.lastIndexOf('.') + 1).toLocaleLowerCase()
        if (fileType != 'doc' && fileType != 'docx' && fileType != 'xls' && fileType != 'xlsx' && fileType != 'ppt' && fileType != 'pptx' && fileType != 'pdf' && fileType != 'jpg' && fileType != 'png' && fileType != 'jpeg' && fileType != 'bmp') {
          wx.showModal({
            title: '系统提示',
            content: '不支持的文件类型，请选择文档和图片文件',
            showCancel: false,
            success(res) {
              if (res.confirm) {} else if (res.cancel) {}
            }
          })
          return
        }
        //存在相同文件判断
        var hasSameFileName = false
        for (var i = 0; i < _this.data.tempFilePathList.length; i++) {
          var hasTempFilePath = _this.data.tempFilePathList[i]
          if (hasTempFilePath != '') {
            if (hasTempFilePath.name.toLowerCase() == tempFilePath.name.toLowerCase() && i != index) {
              hasSameFileName = true
              wx.showModal({
                title: '系统提示',
                content: '新增附件名重复，请重新选择',
                showCancel: false,
                success(res) {
                  if (res.confirm) {} else if (res.cancel) {}
                }
              })
            }
          }
        }
        if (hasSameFileName) {
          return
        }
        //和已有文件存在相同文件判断
        var hasSameFileNameWithOldFiles = false
        _this.data.certificate.attachmentList.forEach(element => {
          if (element.attachmentName.toLowerCase() == tempFilePath.name.toLowerCase()) {
            hasSameFileNameWithOldFiles = true
            wx.showModal({
              title: '系统提示',
              content: '新增附件名与已有附件名相同，确定选择上传时会覆盖相同附件',
              showCancel: true,
              success(res) {
                if (res.confirm) {
                  var tempFilePathListIndexKey = 'tempFilePathList[' + index + ']'
                  var tempFilePathListIndexKeyFileName = 'tempFilePathList[' + index + '].initFileName'
                  _this.setData({
                    [tempFilePathListIndexKey]: tempFilePath,
                    [tempFilePathListIndexKeyFileName]: tempFilePath.name.substring(0, tempFilePath.name.lastIndexOf('.'))
                  })
                  // console.log(_this.data.tempFilePathList)
                } else if (res.cancel) {}
              }
            })
          }
        })
        if (!hasSameFileNameWithOldFiles) {
          var tempFilePathListIndexKey = 'tempFilePathList[' + index + ']'
          var tempFilePathListIndexKeyFileName = 'tempFilePathList[' + index + '].initFileName'
          _this.setData({
            [tempFilePathListIndexKey]: tempFilePath,
            [tempFilePathListIndexKeyFileName]: tempFilePath.name.substring(0, tempFilePath.name.lastIndexOf('.'))
          })

        }
        // console.log(_this.data.tempFilePathList)
      }
    })
  },

  downloadAttach: function (e) {
    wx.showLoading({
      title: '正在下载文件',
      mask: true
    })
    // console.log('url', e.currentTarget.dataset.url)
    var fileType = e.currentTarget.dataset.url.substring(e.currentTarget.dataset.url.lastIndexOf('.') + 1).toLowerCase()
    // console.log(fileType)
    wx.downloadFile({
      url: app.globalData.filePrefix + '/' + e.currentTarget.dataset.url,
      success(res) {
        // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
        if (res.statusCode == 200) {
          wx.hideLoading()
          // console.log('下载', res)
          //如果是文件就打开预览
          if (fileType == 'doc' || fileType == 'docx' || fileType == 'xls' || fileType == 'xlsx' || fileType == 'ppt' || fileType == 'pptx' || fileType == 'pdf') {
            wx.openDocument({
              filePath: res.tempFilePath,
              success: function (res) {
                // console.log('打开文档成功')
              }
            })
          } else if (fileType == 'jpg' || fileType == 'png' || fileType == 'jpeg' || fileType == 'bmp') {
            wx.previewImage({
              urls: [app.globalData.filePrefix + '/' + e.currentTarget.dataset.url] // 需要预览的图片http链接列表
            })

            // wx.saveImageToPhotosAlbum({
            //   filePath: res.tempFilePath,
            //   success(res) {
            //     wx.getSystemInfo({
            //       success (res) {
            //         if(res.platform=='ios'){
            //           wx.showToast({
            //             title: '图片已保存到相册',
            //             icon: 'none',
            //             duration: 1000,
            //             mask: true
            //           })
            //         }
            //       }
            //     })



            //   },
            //   fail: function (err) {
            //     console.log(err);
            //     if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny' || err.errMsg === 'saveImageToPhotosAlbum:fail authorize no response') {
            //       console.log('用户一开始拒绝了，我们想再次发起授权')
            //       console.log('打开设置窗口')

            //       _this.setData({
            //         authorizeShow: true
            //       })

            //       // wx.openSetting({
            //       //   success(settingdata) {
            //       //     console.log(settingdata)
            //       //     if (settingdata.authSetting['scope.writePhotosAlbum']) {
            //       //       console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
            //       //     } else {
            //       //       console.log('获取权限失败，给出不给权限就无法正常使用的提示')
            //       //     }
            //       //   },
            //       //   fail(res) {
            //       //     console.log('打开设置窗口失败，', res)
            //       //   }
            //       // })
            //     }
            //   }


            // })

          } else {
            wx.showModal({
              title: '系统提示',
              content: '暂不支持打开此类文件',
              showCancel: false,
              success(res) {
                if (res.confirm) {} else if (res.cancel) {}
              }
            })
          }

          // wx.openDocument({
          //   filePath: res.tempFilePath,
          //   fileType:'doc',
          //   success: function (res) {
          //     console.log('打开文档成功')
          //   }
          // })


          // wx.saveFile({
          //   tempFilePath: res.tempFilePath,
          //   filePath:wx.env.USER_DATA_PATH+'/1.txt',
          //   success(res) {
          //     console.log('保存',res)
          //   },
          //   fail(res) {
          //     console.log('保存',res)
          //   }
          // })

        } else {
          wx.hideLoading()
          wx.showToast({
            title: '下载失败',
            image: '/images/icon_fail.png',
            duration: 1000,
            mask: true
          })
        }
      },
      fail(res) {
        wx.hideLoading()
        if (res.errMsg == 'downloadFile:fail exceed max file size') {
          wx.showModal({
            title: '系统提示',
            content: '文件过大超出小程序限制，无法下载，请登录pc版档案管理程序查看',
            showCancel: false,
            success(res) {
              if (res.confirm) {} else if (res.cancel) {}
            }
          })
        } else {
          wx.showToast({
            title: '下载失败',
            image: '/images/icon_fail.png',
            duration: 1000,
            mask: true
          })
        }
      }
    })
  },

  updateCertificate: function (e) {

    /*------------校验start------------*/

    if (this.data.certTypeIndex == -1) {
      wx.showModal({
        title: '系统提示',
        content: '证书类型不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.certName) {
      wx.showModal({
        title: '系统提示',
        content: '证书名称不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.certId) {
      wx.showModal({
        title: '系统提示',
        content: '编号不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.projectName) {
      wx.showModal({
        title: '系统提示',
        content: '项目名称不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.certUnit) {
      wx.showModal({
        title: '系统提示',
        content: '颁奖单位不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.beginDate) {
      wx.showModal({
        title: '系统提示',
        content: '发证日期不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (!this.data.certificate.endDate) {
      wx.showModal({
        title: '系统提示',
        content: '到期日期不能为空',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    if (this.data.certificate.beginDate > this.data.certificate.endDate) {
      wx.showModal({
        title: '系统提示',
        content: '发证日期不能大于到期日期',
        showCancel: false,
        success(res) {
          if (res.confirm) {} else if (res.cancel) {}
        }
      })
      return
    }

    /*------------校验end------------*/

    let _this = this

    var deleteAttachMsg = ''
    if (_this.data.deleteAttachmentList.length > 0) {
      deleteAttachMsg = '删除了' + _this.data.deleteAttachmentList.length + '个已有附件，'
    }

    wx.showModal({
      title: '修改确认',
      content: deleteAttachMsg + '确定保存此次修改吗？',
      success(res) {
        if (res.confirm) {
          _this.setData({
            'certificate.modifyPerson': _this.data.userInfo.userName
          })
          //删除不必要传给后台的属性
          delete _this.data.certificate.attachmentList
          //把要删除的附件list属性加上
          _this.data.certificate.deleteAttachmentList = _this.data.deleteAttachmentList
          request.requestAjax('/updateCertificate', _this.data.certificate, '正在保存信息',
            //请求成功回调
            function (res) {
              var uploadResMsg = res.msg
              //开始进行文件上传
              var tempFilePathList = []
              //深拷贝 同时过滤空文件
              for (var i = 0; i < _this.data.tempFilePathList.length; i++) {
                var tempFilePath = _this.data.tempFilePathList[i]
                if (tempFilePath != '') {
                  tempFilePathList.push(_this.data.tempFilePathList[i])
                }
              }
              if (tempFilePathList.length != 0) {
                // console.log(tempFilePathList)
                //构建Promise.all的参数
                var promiseAllFunList = []
                for (var i = 0; i < tempFilePathList.length; i++) {
                  var tempFilePath = tempFilePathList[i]
                  promiseAllFunList.push(_this.uploadCertificateAttach(tempFilePath, _this.data.certificate.id, _this.data.userInfo.userName))
                }
                wx.showLoading({
                  title: '正在上传文件',
                  mask: true
                })
                Promise.all(promiseAllFunList)
                  .then(res => {
                    var msg = ''
                    res.forEach(element => {
                      msg += element
                    })
                    if (msg == '') {
                      wx.hideLoading()
                      _this.getCertificate()
                      wx.showModal({
                        title: '系统提示',
                        content: uploadResMsg,
                        showCancel: false,
                        success(res) {
                          if (res.confirm) {
                            wx.navigateBack()
                          } else if (res.cancel) {}
                        }
                      })
                    } else {
                      wx.hideLoading()
                      _this.getCertificate()
                      wx.showModal({
                        title: '系统提示',
                        content: uploadResMsg + msg,
                        showCancel: false,
                        success(res) {
                          if (res.confirm) {
                            wx.navigateBack()
                          } else if (res.cancel) {}
                        }
                      })
                    }
                  })
                  .catch(e => {
                    wx.hideLoading()
                    _this.getCertificate()
                  })

                // wx.showToast({
                //   title: '修改成功',
                //   icon: 'success',
                //   duration: 1000,
                //   mask: true
                // })

              } else {
                _this.getCertificate()
                wx.showModal({
                  title: '系统提示',
                  content: uploadResMsg,
                  showCancel: false,
                  success(res) {
                    if (res.confirm) {
                      wx.navigateBack()
                    } else if (res.cancel) {}
                  }
                })
              }
            },
            //请求失败回调
            function (res) {
              wx.showModal({
                title: '系统提示',
                content: res.msg,
                showCancel: false,
                success(res) {
                  if (res.confirm) {} else if (res.cancel) {}
                }
              })
            })
        } else if (res.cancel) {}
      }
    })
  },

  deleteCertificate: function (e) {
    let _this = this
    wx.showModal({
      title: '删除确认',
      content: '确定删除此证书吗？',
      success(res) {
        if (res.confirm) {
          _this.setData({
            'certificate.modifyPerson': _this.data.userInfo.userName
          })
          request.requestAjax("/deleteCertificate", {
              "id": _this.data.id,
              "modifyPerson": _this.data.userInfo.userName
            }, "正在加载",
            //请求成功回调
            function (res) {
              wx.showModal({
                title: '系统提示',
                content: '删除证书成功',
                showCancel: false,
                success(res) {
                  if (res.confirm) {
                    wx.navigateBack()
                  } else if (res.cancel) {}
                }
              })
            },
            //请求失败回调
            function (res) {
              wx.showModal({
                title: '系统提示',
                content: res.msg,
                showCancel: false,
                success(res) {
                  if (res.confirm) {} else if (res.cancel) {}
                }
              })
            })
        } else if (res.cancel) {}
      }
    })
  },
  // closeModal: function (e) {
  //   this.setData({
  //     authorizeShow: false
  //   })
  // },

  //上传合同附件
  uploadCertificateAttach: function (tempFilePath, id, modifyPerson) {
    var p = new Promise(function (resolve, reject) {
      var msg = ''
      wx.uploadFile({
        url: app.globalData.urlPrefix + '/uploadCertificateAttach',
        filePath: tempFilePath.path,
        name: 'file',
        formData: {
          //证书id
          'id': id,
          //文件名
          'fileName': tempFilePath.name,
          'modifyPerson': modifyPerson
        },
        //微信的上传文件只要能够访问到服务器 都走success 所以是否成功需要在success中根据后台自定义的code来判断
        success(res) {
          // console.log('res', res)
          let data = JSON.parse(res.data)
          if (data.code != 200) {
            msg += '，文件：' + tempFilePath.name + ' 上传失败'
          }
          resolve(msg)
        },
        fail(res) {
          msg += '，文件：' + tempFilePath.name + ' 上传失败'
          resolve(msg)
        }
      })
    })
    return p
  },

  // //点击保存修改按钮打开修改确认模态框
  // openUpdateConfirm: function () {
  //   this.setData({
  //     updateDialogShow: true
  //   })
  // },
  // //点击修改确认或者取消按钮
  // tapUpdateDialogButton(e) {
  //   console.log(e)
  //   this.setData({
  //     updateDialogShow: false,
  //   })
  //   if (e.detail.item.text == '确定') {
  //     console.log("修改-点了确定")
  //   } else if (e.detail.item.text == '取消') {
  //     console.log("修改-点了取消")
  //   }

  // },

  // //点击删除合同按钮打开修改确认模态框
  // openDeleteConfirm: function () {
  //   this.setData({
  //     deleteDialogShow: true
  //   })
  // },
  // //点击删除确认或者取消按钮
  // tapDeleteDialogButton(e) {
  //   console.log(e)
  //   this.setData({
  //     updateDialogShow: false,
  //   })
  //   if (e.detail.item.text == '确定') {
  //     console.log("删除-点了确定")
  //   } else if (e.detail.item.text == '取消') {
  //     console.log("删除-点了取消")
  //   }

  // },


})